-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: 7431 - code widget Ignore initial lang change to prevent false unsaved changes state #7588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: 7431 - code widget Ignore initial lang change to prevent false unsaved changes state #7588
Conversation
…nsaved changes state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where the code widget incorrectly triggers the onChange callback when initializing the language value from props, causing the CMS to show "unsaved changes" status when loading a document with a saved language setting.
- Added state tracking to identify initial language initialization
- Modified the language change handler to ignore the initial language setting
- Prevented false positive unsaved changes state on document load
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| this.setState({ isLangInitialized: true }); | ||
|
|
||
| this.handleChangeCodeMirrorProps(changedProps, shouldIgnoreLangChange); |
Copilot
AI
Oct 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting isLangInitialized to true should be done after the language change is processed, not before. If handleChangeCodeMirrorProps throws an error, the flag will be incorrectly set to true even though initialization didn't complete successfully.
| this.setState({ isLangInitialized: true }); | |
| this.handleChangeCodeMirrorProps(changedProps, shouldIgnoreLangChange); | |
| this.handleChangeCodeMirrorProps(changedProps, shouldIgnoreLangChange); | |
| this.setState({ isLangInitialized: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with this, the ordering here is intentional for graceful failure; if for some reason handleChangeCodeMirrorProps errors we would rather falsely report changes when there are none than potentially ignore actual changes that have been made.
|
@dlford please check if Copilot makes sense here. |
Co-authored-by: Copilot <[email protected]>
…nsaved changes state (decaporg#7588) * fix: 7431 - code widget Ignore initial lang change to prevent false unsaved changes state * 7588: apply copilot nitpick Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Martin Jagodic <[email protected]> Co-authored-by: Copilot <[email protected]>
fixes #7431
Summary
The code widget executes the
onChangecallback anytimelangis changed, including when initializing the value fromprops. This causes the CMS to act as if there are unsaved changes any time a document is loaded with a saved language in the code widget.Test plan
Using the below config and index, create a new blog post and add a code component, set the language and save. Reload the page, you should see the "changes saved" message in the top left of the CMS instead of "unsaved changes".
config.ymlindex.htmlChecklist
Please add a
xinside each checkbox: